package com.shrct.businessprocess.product;

import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductPurchaseInfo;
import com.shrct.businessprocess.product.events.RCIdentifiablePhysicalProductEntryEventsListener;
import com.shrct.businessprocess.product.impl.RCIdentifiablePhysicalProductPurchaseInfoImpl;
import com.shrct.businessprocess.purchase.RCPurchaseOrderItem;
import edu.fudan.mylang.pf.IGenericQuery;
import edu.fudan.mylang.pf.event.BaseEntityEventsListener;
import edu.fudan.mylang.utils.DateUtil;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.product.RCProductPurchaseInfoBuilder4IdentifiablePhysicalProduct")
public class RCProductPurchaseInfoBuilder4IdentifiablePhysicalProduct extends BaseEntityEventsListener<RCIdentifiablePhysicalProductEntry> implements RCIdentifiablePhysicalProductEntryEventsListener {
  public void _inStock(final RCIdentifiablePhysicalProductEntry entity, final RCPurchaseOrderItem orderItem) {RCIdentifiablePhysicalProductPurchaseInfo rCIdentifiablePhysicalProductPurchaseInfo=RCIdentifiablePhysicalProductPurchaseInfoImpl.create(entity,getObjectFactory());
    final Procedure1<RCIdentifiablePhysicalProductPurchaseInfo> _function = new Procedure1<RCIdentifiablePhysicalProductPurchaseInfo>() {
        public void apply(final RCIdentifiablePhysicalProductPurchaseInfo it) {
          it.setOrderItem(orderItem);
          Date _day = DateUtil.today();
          it.setInStockDate(_day);
          Integer _count = entity.getCount();
          it.setInStockQuantity(_count);
        }
      };
    ObjectExtensions.<RCIdentifiablePhysicalProductPurchaseInfo>operator_doubleArrow(rCIdentifiablePhysicalProductPurchaseInfo, _function);
  }
  
  public void _deliver(final RCIdentifiablePhysicalProductEntry entity, final RCEnterprise enterprise) {
    IGenericQuery<RCIdentifiablePhysicalProductPurchaseInfo> query=getObjectFactory().createGenericQuery(RCIdentifiablePhysicalProductPurchaseInfo.class,"select e from com.shrct.businessprocess.product.impl.RCIdentifiablePhysicalProductPurchaseInfoImpl as e   where ((e.product) = (:entity)) and  e.active = 1      ").setParameter("entity",entity);
    RCIdentifiablePhysicalProductPurchaseInfo _uniqueResult = query.uniqueResult();
    final Procedure1<RCIdentifiablePhysicalProductPurchaseInfo> _function = new Procedure1<RCIdentifiablePhysicalProductPurchaseInfo>() {
        public void apply(final RCIdentifiablePhysicalProductPurchaseInfo it) {
          Date _day = DateUtil.today();
          it.setDeliverDate(_day);
          Integer _count = entity.getCount();
          it.setDeliverQuantity(_count);
          Integer _count_1 = entity.getCount();
          it.addDeliverTarget(_count_1, enterprise);
        }
      };
    ObjectExtensions.<RCIdentifiablePhysicalProductPurchaseInfo>operator_doubleArrow(_uniqueResult, _function);
  }
  
  public void _return(final RCIdentifiablePhysicalProductEntry entity) {
    IGenericQuery<RCIdentifiablePhysicalProductPurchaseInfo> query=getObjectFactory().createGenericQuery(RCIdentifiablePhysicalProductPurchaseInfo.class,"select e from com.shrct.businessprocess.product.impl.RCIdentifiablePhysicalProductPurchaseInfoImpl as e   where ((e.product) = (:entity)) and  e.active = 1      ").setParameter("entity",entity);
    RCIdentifiablePhysicalProductPurchaseInfo _uniqueResult = query.uniqueResult();
    final Procedure1<RCIdentifiablePhysicalProductPurchaseInfo> _function = new Procedure1<RCIdentifiablePhysicalProductPurchaseInfo>() {
        public void apply(final RCIdentifiablePhysicalProductPurchaseInfo it) {
          it.setDeliverQuantity(Integer.valueOf(0));
        }
      };
    ObjectExtensions.<RCIdentifiablePhysicalProductPurchaseInfo>operator_doubleArrow(_uniqueResult, _function);
  }
  
  public void _import(final RCIdentifiablePhysicalProductEntry entity) {
  }
  
  public void _rmaReplace(final RCIdentifiablePhysicalProductEntry entity) {
  }
  
  public void _rmaImport(final RCIdentifiablePhysicalProductEntry entity) {
  }
  
  public void _cancelInStock(final RCIdentifiablePhysicalProductEntry entity) {
  }
}
